﻿using BusinessBingo.CommandHandlers;
using BusinessBingo.CommandHandlers.Base;
using Castle.Core;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;

namespace BusinessBingo.Installer
{
    /// <summary>
    /// WindsorInstaller for ServiceLayer project
    /// </summary>
    public class CommandHandlerInstaller : IWindsorInstaller
    {
        private LifestyleType _lifestyleType;

        public CommandHandlerInstaller(LifestyleType lifestyleType)
        {
            this._lifestyleType = lifestyleType;
        }

        /// <summary>
        /// Register ServiceLayer componentes in container
        /// </summary>
        /// <param name="container">IoC Container where compontents are registered</param>
        /// <param name="store">IoC Store for configuration </param>
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(AllTypes.FromAssembly(typeof(BaseCommandHandler).Assembly).
                                   Pick().
                                   WithService.
                                   FirstInterface().
                                   Configure(x => x.LifeStyle.Is(this._lifestyleType)));
        }
    }
}
